package com.kalua.list.harvester.parser;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Maps;
import com.kalua.list.domainmodel.KaluaException;
import com.kalua.list.domainmodel.TextIdentifier;

public class ContentLinkExtractorFactoryImpl implements ContentLinkExtractorFactory {

	private Map<TextIdentifier, ContentLinkExtractor> linkExtractorMap;
		
	public ContentLinkExtractorFactoryImpl(List<ContentLinkExtractor> extractors) { 
		this.linkExtractorMap = Maps.newHashMap();
		for (ContentLinkExtractor extractor : extractors) {
			this.linkExtractorMap.put(extractor.getRetailerId(), extractor);
		}
	}
		
	@Override
	public ContentLinkExtractor createExtractor(TextIdentifier retailerId) {
		ContentLinkExtractor prototype = this.linkExtractorMap.get(retailerId);
		if (prototype == null)
			throw new KaluaException("No extractor implementation specified for " + retailerId);
		return prototype.fromPrototype();
	}
}